package cn.sccl.dirms.topo.model;

import cn.sccl.common.exception.BusinessException;
import cn.sccl.common.model.BaseModel;

/**
 * 存储拓扑发现结果，以json格式存储，每次发现存储一次记录
 * 数据库表 T_DISCOVERY_RESULT 的实体对象
 * Created by julei on 2017-10-17.
 */
public class DiscoveryResult extends BaseModel {
    /**
     * 表名
     */
    public final static String TABLE_NAME = "t_discovery_result";
    private static final long serialVersionUID = -5067734288758796679L;

    private String ruleDetail;//发现规则，json格式
    private byte[] deviceList;//发现设备列表，json格式，对应DeviceInfo类
    private byte[] linkList;//发现链路列表，json格式，对用LinkInfo类
    private String logId;//发现日志ID

    public void setRuleDetail(String ruleDetail) {
        this.ruleDetail = ruleDetail;
    }

    public String getRuleDetail() {
        return this.ruleDetail;
    }

    public void setDeviceList(byte[] deviceList) {
        this.deviceList = deviceList;
    }

    public byte[] getDeviceList() {
        return this.deviceList;
    }

    public void setLinkList(byte[] linkList) {
        this.linkList = linkList;
    }

    public byte[] getLinkList() {
        return this.linkList;
    }

    public void setLogId(String logId) {
        this.logId = logId;
    }

    public String getLogId() {
        return this.logId;
    }

    /**
     * clone一个对象。
     *
     * @param cls 需要克隆的对象类型，只能是当前类的子类
     * @param <T>
     * @return
     * @throws IllegalAccessException
     * @throws InstantiationException
     */
    public <T extends DiscoveryResult> T clone(Class<T> cls) {
        try {
            T t = cls.newInstance();
            t.setId(this.getId());
            t.setDeleteFlag(deleteFlag);
            t.setCreateTime(this.getCreateTime());
            t.setUpdateTime(this.getUpdateTime());
            t.setRuleDetail(this.getRuleDetail());
            t.setDeviceList(this.getDeviceList());
            t.setLinkList(this.getLinkList());
            t.setLogId(this.getLogId());
            return t;
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("对象克隆失败，请克隆的目标对象是否具有无参的构造函数。", e.getCause());
        }
    }
}